<template>
	<view>
		<view class="title">
			<view class="search">
				<view class="input">
					<input type="text" placeholder="搜一搜" v-model="params.name" confirm-type="search" @confirm="search"/>
					<i class="iconfont" style="margin-left: 60rpx;" @click="search">&#xe60a</i>
				</view>
			</view>
			<view class="tab" v-if="isShow===true">
				<view class="tabs">
					<view v-for="(item, index) in tablist" :key="index" class="tabs-1"
						:class="{ 'active': isSelected === item.id }" @click="selectTab(item.id)">
						{{ item.name }}
					</view>
				</view>
				<view class="more">
					<view class="btn" @click="more">
						更多 <u-icon name="arrow-right" size="14" color="#d2d2d2" style="margin-left: 10rpx;"></u-icon>
					</view>
				</view>
			</view>
			<view class="to-btn" v-if="isShow===true" @click="goPage('launch/launch')">
				<image src="https://pw.qyang.cc/static/btn_add.png"></image>
			</view>
			<view class="content" v-if="activityList.length>0">
				<view class="activityList" v-for="(item,index) in activityList" :key="index" @click="goDetail(item)">
					<view class="title">
						<view class="title-tab" v-if="item.is_recommend == 1">
							推荐
						</view>
						<view class="title-text">
							{{item.title}}
						</view>
					</view>
					<view class="status">
						<view class="status status0" v-if="item.activity_status == 1">
							筹备中
						</view>
						<view class="status status1" v-if="item.activity_status == 2">
							报名中
						</view>
						<view class="status status2" v-if="item.activity_status == 3">
							已结束
						</view>
					</view>
					<view class="image">
						<image :src="rq.imgUrl(item.image)" mode="aspectFill"></image>
						<view class="btn" v-if="item.activity_status == 2">
							<image src="https://pw.qyang.cc/static/svg/button.svg"
								style="width: 30rpx;height: 30rpx;margin-right: 10rpx;">
							</image> 参与
						</view>
					</view>
					
					<view class="con">
						<view class="con1">
							<image src="https://pw.qyang.cc/static/svg/biao.svg" mode="aspectFill"
								style="width: 30rpx;height: 30rpx;margin-right: 15rpx;"></image>
							{{item.issue}}
						</view>
						<view class="con1">
							<image src="https://pw.qyang.cc/static/svg/dingwei.svg" mode="aspectFit"
								style="width: 30rpx;height: 30rpx;margin-right: 15rpx;"></image>{{item.address}}
						</view>
						<view class="con1 con2" v-if="item.status != 0">
							<view class="con2-img">
								<image :src="rq.imgUrl(i)" v-for="i,index in item.join_avatar" :key="index"></image>
							</view>
							<view class="con2-text">
								累计 <span style="color: #FF7883;">{{item.join_num}}人</span> 报名
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tablist: [{
						id:1,
						name: "筹备中",
					},
					{
						id:2,
						name: "报名中",
					},
					{
						id:3,
						name: "已结束",
					},
				],
				activityList: [],
				isSelected: 2,
				isShow: true,
				total:0,
				params:{
					limit:10,
					page:1,
					activity_status:2  	//活动状态 1=筹备中 2=报名中 3=已结束 4=更多  空=全部
				}
			};
		},
		onLoad() {
			let dw = uni.getStorageSync('dw')
			this.params.city_id = dw.id
			this.getList(this.params)
		},
		onPullDownRefresh() {
			this.params.page = 1;
			uni.hideNavigationBarLoading();			
			this.getList()
		},
		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom() {
			if(this.activityList.length<this.total){
				this.getList(true)
				this.page++;
			}
		},
		methods: {
			getList(more){
				this.rq.getData('User_Activity/index',this.params).then(res=>{
					if(more){
						this.activityList = [...this.activityList,...res.data.data]
					}else{
						this.activityList = res.data.data
					}
					this.total = res.data.total
					uni.stopPullDownRefresh();
				}).catch(err=>{
					uni.stopPullDownRefresh();
				})
			},
			search(){
				this.params.page = 1
				this.getList()
			},
			selectTab(id) {
				this.isSelected = id;
				this.params.activity_status = id
				this.params.page = 1
				this.getList()
			},
			more() {
				this.isShow = false;
				this.params.activity_status = 4
				this.params.page = 1
				this.getList()
			},
			goDetail(item) {
				uni.navigateTo({
					url: "/subpages/activity/detail?id=" + item.id,
				});
			},
			goPage(url) {
				// 发起活动
				uni.navigateTo({
					url: `/subpages/${url}`,
				});
			},
		},
	};
</script>

<style lang="scss">
	.title {
		background-color: #ffffff;
	}

	.to-btn {
		position: fixed;
		z-index: 1;
		right: 10rpx;
		top: 700rpx;
		// background-color:#FF7681 ;
		border-radius: 50%;
		width: 100rpx;
		height: 100rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		image {
			width: 100%;
			height: 100%;
		}
		// image {
		// 	width: 44rpx;
		// 	height: 44rpx;
		// }
	}

	.tab {
		position: relative;
		display: flex;

		.more {
			font-family: 阿里巴巴普惠体 2;
			font-size: 14px;
			font-weight: normal;
			line-height: 15px;
			letter-spacing: 0px;
			color: #333333;
			width: 26%;
			margin-right:20rpx;
			display: flex;
			align-items: center;
			justify-content: flex-end;

			.btn {
				display: flex;
				align-items: center;
			}
		}

		.tabs {
			background-color: #ffffff;
			display: flex;
			justify-content: center;
			height: 60rpx;
			width: 70%;
			margin-left: 44rpx;
			.tabs-1 {
				flex: 1;
				justify-content: center;
				align-items: center;
				display: flex;

				font-size: 14px;
				font-weight: normal;
				line-height: 15px;
				letter-spacing: 0px;

				color: #999999;
			}

			.tabs-1.active {
				position: relative;
				font-size: 15px;
				font-weight: 600;
				line-height: 15px;
				letter-spacing: 0px;
				transition: all 0.3s ease;
				color: #333333;
			}

			.tabs-1.active::after {
				border-radius: 3px;
				opacity: 1;
				background: #ff7883;
				content: "";
				position: absolute;
				bottom: 0;
				left: 50%;
				transform: translateX(-50%);
				width: 55rpx;
				height: 3px;
				transition: width 0.3s ease, opacity 0.3s ease;
			}
		}
	}

	.content {
		padding: 20rpx 30rpx 100rpx 30rpx;
		position: relative;
		background-color: #f4f4f4;

		.activityList {
			margin-bottom: 30rpx;
			border-radius: 10px;
			background-color: #ffffff;
			width: 100%;
			// height: 686rpx;
			display: flex;
			flex-direction: column;
			align-items: flex-start;

			.title {
				font-size: 14px;
				font-weight: 600;
				line-height: 2px;
				letter-spacing: 0px;
				color: #333333;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
				// // width: 600rpx;
				// padding: 30rpx;
				// position: relative;
				// margin: 10rpx 0;
				padding: 10rpx 28rpx;
				position: relative;
				margin: 10rpx 0;
				width: 550rpx;
				display: flex;
				align-items: center;

				.title-tab {
					width: 50px;
					height: 40rpx;
					border-radius: 4px;
					opacity: 1;

					background: #ff7681;
					font-size: 12px;
					font-weight: normal;
					line-height: 12px;
					text-align: center;
					letter-spacing: 0px;
					color: #ffffff;
					margin-right:20rpx;
					display: flex;
					align-items: center;
					justify-content: center;
				}

				.title-text {
					width: 500rpx;
					height: 40rpx;
					line-height: 40rpx;
					text-overflow: ellipsis;
					overflow: hidden;
					white-space: nowrap;
				}
			}

			.image {
				width: 100%;
				height: 400rpx;
				position: relative;
				image {
					width: 100%;
					height: 400rpx;
				}
			}

			.status {
				position: absolute;
				right: 0;
				margin-right: 30rpx;
				width: 54.64px;
				height: 24.72px;
				border-radius: 0px 8px 0px 8px;
				opacity: 1;

				font-size: 13px;
				font-weight: 500;
				line-height: 12px;
				text-align: center;
				letter-spacing: 0px;
				// background: #84E28C;
				color: #ffffff;
				display: flex;
				align-items: center;
				justify-content: center;

				.status0 {
					background: #84e28c;
					margin-right: -1rpx;
				}

				.status1 {
					background: #ae9cfe;
					margin-right: -1rpx;
				}

				.status2 {
					background: rgba(153, 153, 153, 0.1);
					color: #999999;
					margin-right: -1rpx;
				}
			}

			.btn {
				left: 50%;
				transform: translateX(-50%);
				position: absolute;
				width: 115px;
				height: 38px;
				display: flex;
				align-items: center;
				justify-content: center;
				border-radius: 99px;
				opacity: 1;
				bottom: -16px;
				// margin-top: 445rpx;
				background: #ff7681;
				font-family: PingFang SC;
				font-size: 18px;
				font-weight: normal;
				line-height: 18px;
				letter-spacing: 0px;
				color: #ffffff;
				text-shadow: 0px 1px 4px rgba(108, 37, 37, 0.25);
			}

			.con {
				width: 100%;
				padding: 20rpx 0;

				.con1 {
					font-family: 阿里巴巴普惠体 2;
					font-size: 13px;
					font-weight: normal;
					line-height: 12px;
					letter-spacing: 0px;
					margin: 20rpx;
					color: #333333;
					display: flex;
					align-items: center;
				}

				.con2 {
					display: flex;

					.con2-img {
						width: 460rpx;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;

						image {
							width: 21px;
							height: 21px;
							margin-right: 10rpx;
							border-radius: 50%;
						}
					}

					.con2-text {
						font-family: PingFang SC;
						font-size: 14px;
						font-weight: normal;
						line-height: 12px;
						letter-spacing: 0px;

						font-variation-settings: "opsz" auto;
						/* 累计 */
						color: #000000;
					}
				}
			}
		}
	}

	.search {
		width: 92%;
		height: 35px;
		border-radius: 99px;
		opacity: 1;

		background: #fcf9f9;

		box-sizing: border-box;
		border: 1px solid #333333;
		margin: 0 auto 20rpx;
		display: flex;
		align-items: center;

		.input {
			display: flex;
			align-items: center;
			// justify-content: center;
			width: 100%;

			input {
				padding-left: 30rpx;
				font-family: 阿里巴巴普惠体 2;
				font-size: 13px;
				font-weight: normal;
				line-height: 13px;
				letter-spacing: 0px;
				color: #999999;
				width: 80%;
			}
		}
	}
</style>